package com.example.onion.hxchat.activity;

import androidx.annotation.NonNull;
import androidx.appcompat.app.ActionBar;
import androidx.appcompat.app.AppCompatActivity;
import androidx.appcompat.widget.Toolbar;

import android.content.Intent;
import android.database.sqlite.SQLiteDatabase;
import android.os.Bundle;
import android.util.Log;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.TextView;
import android.widget.Toast;

import com.example.databean.User;
import com.example.onion.hxchat.util.HttpUtils;
import com.example.onion.hxchat.util.MyLocalDatabaseHelper;
import com.example.superyi.myteam.R;
import com.google.gson.Gson;

import java.io.IOException;

import okhttp3.FormBody;
import okhttp3.Request;

/**
 * 需要调用申请加好友活动页面，需要给出聊天对象userId（加前缀scan)
 * 和用户名userName（传递到本页面的key值应该是scanUserName）
 * <p>
 * friendName = getIntent().getStringExtra("scanUserName");
 * friendUserId = getIntent().getStringExtra("scanUserId");
 */
public class ScanUserActivity extends AppCompatActivity implements View.OnClickListener {

    private String friendName;//好友昵称
    private String friendUserId;//好友id(系统中的用户id)
    private String friendUserSpy;

    public void initData() {
        friendName = getIntent().getStringExtra("scanUserName");
        friendUserId = getIntent().getStringExtra("scanUserId");
        friendUserSpy = getIntent().getStringExtra("scanUserSpy");
    }

//    private int version = 4;
    private ImageView userScamImg;

    private TextView userScanNameTv;

    private TextView userScanInfoTv;

    private Button userScanSendInfo;

    private Button userScanApply;

    private Toolbar toolbar;


    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_scan_user);
        initData();
        initView();
    }

    private void initView() {
        userScamImg = findViewById(R.id.user_img_iv);
        userScanNameTv = findViewById(R.id.user_name_tv);
        userScanInfoTv = findViewById(R.id.user_info_tv);
        userScanSendInfo = findViewById(R.id.scan_send_info_btn);
        userScanApply = findViewById(R.id.scan_apply_btn);
        userScanNameTv.setText(friendName);//根据得到的Name设置ui
        userScanInfoTv.setText(friendUserSpy);
        userScamImg.setOnClickListener(this);
        userScanNameTv.setOnClickListener(this);
        userScanInfoTv.setOnClickListener(this);
        userScanSendInfo.setOnClickListener(this);
        userScanApply.setOnClickListener(this);
        toolbar = findViewById(R.id.scan_user_toolbar);
        setSupportActionBar(toolbar);
        ActionBar actionBar = getSupportActionBar();
        if (actionBar != null) {
            actionBar.setDisplayHomeAsUpEnabled(true);
            actionBar.setDisplayShowTitleEnabled(false);
        }
//        toolbar.setNavigationOnClickListener(new View.OnClickListener() {
//            @Override
//            public void onClick(View v) {
//                Log.d("Back","scan点击了返回");
//                finish();
//            }
//        });
    }

    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        getMenuInflater().inflate(R.menu.toolbar_scan_user_menu, menu);
        return true;
    }

    @Override
    public boolean onOptionsItemSelected(@NonNull MenuItem item) {
        switch (item.getItemId()) {
            case android.R.id.home://系统自带的返回箭头的资源id
                finish();
                Log.d("ScanActivity", "返回键");
                break;
            case R.id.scan_more_user_info://浏览用户页面的详细信息菜单项
                Intent intent = new Intent(ScanUserActivity.this, UserDetailActivity.class);
                //传递给查看用户详细界页面的用户名称（最好根据需要传递到的不同的页面，命名kEY，此处需要传递到查看用户详细界面，加前缀detail+UserName）
                intent.putExtra("detailUserName", friendName);
                intent.putExtra("detailUserId", friendUserId);
                intent.putExtra("detailUserSpy", friendUserSpy);
                startActivity(intent);
                Log.d("ScanActivity", "点击详细信息");
                break;
            default:
                break;
        }
        return true;
    }

    @Override
    public void onClick(View v) {
        Intent intent = null;
        switch (v.getId()) {
            case R.id.user_img_iv:
                Toast.makeText(this, "点击了头像", Toast.LENGTH_SHORT).show();
                break;
            case R.id.user_name_tv:
                Toast.makeText(this, "点击了姓名", Toast.LENGTH_SHORT).show();
                break;
            case R.id.user_info_tv:
                Toast.makeText(this, "点击了信息", Toast.LENGTH_SHORT).show();
                break;
            case R.id.scan_send_info_btn:
                intent = new Intent(this, MsgTestActivity.class);
                //传递给聊天页面的用户名称（最好根据需要传递到的不同的页面，命名kEY，此处需要传递到聊天界面，加前缀chat+UserName）
                intent.putExtra("chatUserName", friendName);
                intent.putExtra("chatUserId", friendUserId);
                startActivity(intent);
                Toast.makeText(this, "点击了发送信息", Toast.LENGTH_SHORT).show();
                break;
            case R.id.scan_apply_btn:
                intent = new Intent(this, ApplyFriendActivity.class);
                //传递给验证码输入页面的用户名称（最好根据需要传递到的不同的页面，命名kEY，此处需要传递到申请加好友界面，加前缀apply+UserName）
                intent.putExtra("applyUserName", friendName);
                intent.putExtra("applyUserId", friendUserId);
                intent.putExtra("applyUserSpy", friendUserSpy);
                startActivity(intent);
                Toast.makeText(this, "点击了添加好友", Toast.LENGTH_SHORT).show();
                break;
            default:
                break;
        }
    }




}
